﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 加密程序
{
    internal class Coop
    {
        private const string 初始化变量 = "WIN_EX";

        private const string 时间变量 = "WIN_ET";

        public static bool Initial()
        {
            try
            {
                Environment.SetEnvironmentVariable("WIN_EX", "1", EnvironmentVariableTarget.User);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool AuthInitail()
        {
            string environmentVariable = Environment.GetEnvironmentVariable("WIN_EX", EnvironmentVariableTarget.User);
            if (environmentVariable == null)
            {
                return false;
            }
            return true;
        }

        public static bool InitialTime(DateTime datetime)
        {
            Environment.SetEnvironmentVariable("WIN_ET", datetime.ToString("d"), EnvironmentVariableTarget.User);
            return true;
        }

        public static bool GetTime()
        {
            string environmentVariable = Environment.GetEnvironmentVariable("WIN_ET", EnvironmentVariableTarget.User);
            DateTime result;
            if (DateTime.TryParse(environmentVariable, out result) && DateTime.Now < result)
            {
                return true;
            }
            return false;
        }
    }
}
